﻿using System;
using System.Windows.Forms;
using Client.TopLevel;

namespace PersApp
{
    public partial class LoginForm : Form
    {
        private const string ErrorText = "Неверный логин или пароль!";

        private IManagerEmployee employee = null;

        public IManagerEmployee Employee
        {
            get { return employee; }
        }

        public LoginForm()
        {
            InitializeComponent();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void buttonEnter_Click(object sender, EventArgs e)
        {
            string login = this.textBoxLogin.Text;
            string password = this.textBoxPassword.Text;

            employee = new UserManager(login, password);

            if (employee.LogIn())
            {
                Close();
            }
            else
            {
                employee = null;
                textBoxPassword.Text = string.Empty;
                labelError.Text = ErrorText;
            }
        }

        private void LoginForm_Load(object sender, EventArgs e)
        {
            if (BuildConfig.AUTO_LOGIN)
            {
                textBoxLogin.Text = "Пупкин";
                textBoxPassword.Text = "Пупкин";
                buttonEnter.PerformClick();
            }
        }
    }
}
